﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Gollie.Administration;
using NLog;

namespace Gollie.Administration.Service
{
	public class AdministrationService : IAdministrationService
	{
		public void Nop() { }

		public static void DeleteOldFiles(string folder, string filter, int ageInDays, Logger logger)
		{
			string[] files = Directory.GetFiles(folder, filter, SearchOption.TopDirectoryOnly);

			DateTime limit = DateTime.Now.AddDays(-ageInDays);

			foreach (string file in files.Where(f => File.GetCreationTime(f) < limit))
			{
				logger.Info("Deleting {0}", file);
				File.Delete(file);
			}
		}
	}
}
